/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import javax.swing.JOptionPane;
import sistemadeleiloes.model.Produto;
public class ILeilaoImpl {

    ILeilao l = null;
    Produto p = new Produto();

    public void iniciaLeilao() throws NotBoundException, MalformedURLException {
        try {
            LocateRegistry.getRegistry("192.168.0.102");
            l = (ILeilao) Naming.lookup("rmi://localhost:9999/LeilaoImpl");

        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void efetuarLance(double lance, int idUsuario, int idLeilao) throws RemoteException, NotBoundException, MalformedURLException {
        try {
            iniciaLeilao();
            if (l.efetuarLance(lance, idUsuario, idLeilao) == true) {
                System.out.println("OK");
            } else {
                System.out.append("Erro");
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void encerrar(int id, String senha) throws RemoteException, NotBoundException, MalformedURLException {
        iniciaLeilao();

        JOptionPane.showMessageDialog(null, l.encerrarLeilao(id, senha));

    }

}
